<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="chekForm.js"></script>
    <script>
        //验证姓名文本框
        function checkName() {
            return checkFormElement("name","nameSpan",/^[a-zA-Z\u4e00-\u9fa5]{2,}$/,"姓名必须是两位以上的汉字或字母");
        }

        function checkTel() {
            return checkFormElement("tel","telSpan",/^1[3578]\d{9}$/,"电话必须为13、15、17、18开始的11位数");
        }

        function checkForm() {
            var passName = checkName();
            var passTel = checkTel();
            return passName && passTel;
        }

        let array = [{id:1,name:"j178"},{id:2,name:"j179"},{id:3,name:"j177"}];
        window.onload = function () {
            let selectObj = document.getElementById("classSelect");
            let str = "";
            for(var i=0;i<array.length;i++){
                var obj = array[i];
                // str += "<option value='"+obj.id+"'>"+obj.name+"</option>";
                str += `<option value='${obj.id}'>${obj.name}</option>`;
            }
            selectObj.innerHTML = str;
        }

    </script>
</head>
<body>
    <form action="add" method="get" onsubmit="return checkForm();">
        姓名：<input type="text" id="name" name="name" onblur="checkName()"><span id="nameSpan"></span><br>
        电话：<input type="text" id="tel" name="tel" onblur="checkTel();"><span id="telSpan"></span><br>
        <input type="submit" value="提交">
    </form>

    <select id="classSelect"></select>
    <input type="text" onkeypress="return false">

</body>
</html>